﻿package glam.skins;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.Lib;
import fpc.styles.skins.ITextBackgroundSkin;
import fpc.styles.skins.NullTextBackgroundSkin;
import fpc.utils.IFactory;
import fpc.utils.ScaledBitmap;
import glam.Primitives;

class GlamTextBackground implements IFactory<ITextBackgroundSkin>
{
	var _bitmapData:BitmapData;
	
	public function new(primitives:Primitives = null)
	{
		if (primitives == null)
		{
			primitives = Primitives.defaultPrimitives;
		}
		_bitmapData = primitives.getTextBackground();
	}
	
	public function create():ITextBackgroundSkin
	{
		return new GlamTextBackgroundSkin(_bitmapData);
	}
}

class GlamTextBackgroundSkin extends NullTextBackgroundSkin
{
	var _shape:ScaledBitmap;
	
	public function new(bitmapData:BitmapData)
	{
		super();
		_shape = new ScaledBitmap(Lib.as(object, Shape).graphics, bitmapData);
	}
	
	public override function setSize(width:Int, height:Int)
	{
		_shape.setBounds( -1, -1, width + 2, height + 2);
	}
}